#!/usr/bin/env python
# -*- coding: utf-8 -*-

# @Time     :2020/10/15
# @Author   :Changshu
# @File     :Exercise_290.py

# 290. 单词规律
# 给定一种规律 pattern 和一个字符串 str ，判断 str 是否遵循相同的规律。

def wordPattern(pattern: str, s: str) -> bool:
	if pattern is None and s is None:
		return True
	if pattern is None or s is None:
		return False
	slist=s.split(' ')
	d={}
	n=len(pattern)
	if n!=len(slist):
		return False
	for i in range(0,n):
		if pattern[i] in d:
			if d[pattern[i]]!=slist[i]:
				return False
		else:
			if slist[i] in d.values():
				return False
			d[pattern[i]] = slist[i]
	return True

if __name__ == '__main__':
	pattern = "abba"
	s = "dog dog dog dog"
	print(wordPattern(pattern,s))


